package com.qr.service.wmyh.impl;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.mapping.ResultMapping;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.krui.helper.db.DBHelper;
import cn.krui.helper.db.DataPage;
import com.qr.bean.wmyh.JbrUsers;
import com.qr.bean.wmyh.JbrUsersView;
import com.qr.controller.WmyhBase;
import com.qr.mapper.wmyh.JbrUsersMapper;
import com.qr.mapper.wmyh.JbrUsersMapperView;
import com.qr.service.wmyh.JbrUsersService;
//import org.apache.dubbo.config.annotation.Service;

/**
 * @author: zc
 * email: zc8023zs@163.com
 * create_time: 2020/8/11 13:04:29
 */
@Service
//@Service(version = "1.0.0",group="dubbo")
public class JbrUsersServiceImpl implements JbrUsersService{
    @Autowired
    private JbrUsersMapper jbrUsersMapper;

    @Autowired
    private JbrUsersMapperView jbrUsersMapperView;
    
    @Autowired
    private DBHelper dbHelper;

    /**
     * 构造查询条件
     */
    private QueryWrapper<JbrUsers> InitWrapper(JbrUsers where){
        QueryWrapper<JbrUsers> whereWrapper = new QueryWrapper<JbrUsers>();
        if(where.getId()!=null){
			whereWrapper.eq("id",where.getId());
		}
        if(where.getUser_name()!=null){
			whereWrapper.eq("user_name",where.getUser_name());
		}
        if(where.getMobile()!=null){
			whereWrapper.eq("mobile",where.getMobile());
		}
        if(where.getLogin_pass()!=null){
			whereWrapper.eq("login_pass",where.getLogin_pass());
		}
        if(where.getMobile_check()!=null){
			whereWrapper.eq("mobile_check",where.getMobile_check());
		}
        if(where.getEmail()!=null){
			whereWrapper.eq("email",where.getEmail());
		}
        if(where.getEmail_check()!=null){
			whereWrapper.eq("email_check",where.getEmail_check());
		}
        if(where.getScore()!=null){
			whereWrapper.eq("score",where.getScore());
		}
        if(where.getScore_total()!=null){
			whereWrapper.eq("score_total",where.getScore_total());
		}
        if(where.getAmount()!=null){
			whereWrapper.eq("amount",where.getAmount());
		}
        if(where.getPay_pass()!=null){
			whereWrapper.eq("pay_pass",where.getPay_pass());
		}
        if(where.getAlias()!=null){
			whereWrapper.eq("alias",where.getAlias());
		}
        if(where.getSex()!=null){
			whereWrapper.eq("sex",where.getSex());
		}
        if(where.getBirthday()!=null){
			whereWrapper.eq("birthday",where.getBirthday());
		}
        if(where.getQq()!=null){
			whereWrapper.eq("qq",where.getQq());
		}
        if(where.getReg_date()!=null){
			whereWrapper.eq("reg_date",where.getReg_date());
		}
        if(where.getReg_source()!=null){
			whereWrapper.eq("reg_source",where.getReg_source());
		}
        if(where.getNote()!=null){
			whereWrapper.eq("note",where.getNote());
		}
        if(where.getIsok()!=null){
			whereWrapper.eq("isok",where.getIsok());
		}
        if(where.getImg_url()!=null){
			whereWrapper.eq("img_url",where.getImg_url());
		}
        if(where.getQq_id()!=null){
			whereWrapper.eq("qq_id",where.getQq_id());
		}
        if(where.getQq_name()!=null){
			whereWrapper.eq("qq_name",where.getQq_name());
		}
        if(where.getQq_img_url()!=null){
			whereWrapper.eq("qq_img_url",where.getQq_img_url());
		}
        if(where.getWx_id()!=null){
			whereWrapper.eq("wx_id",where.getWx_id());
		}
        if(where.getWx_name()!=null){
			whereWrapper.eq("wx_name",where.getWx_name());
		}
        if(where.getWx_img_url()!=null){
			whereWrapper.eq("wx_img_url",where.getWx_img_url());
		}
        if(where.getXcx_id()!=null){
			whereWrapper.eq("xcx_id",where.getXcx_id());
		}
        if(where.getXcx_formid()!=null){
			whereWrapper.eq("xcx_formid",where.getXcx_formid());
		}
        if(where.getUnion_id()!=null){
			whereWrapper.eq("union_id",where.getUnion_id());
		}
        if(where.getGrade_id()!=null){
			whereWrapper.eq("grade_id",where.getGrade_id());
		}
        if(where.getStart_time()!=null){
			whereWrapper.eq("start_time",where.getStart_time());
		}
        if(where.getDue_time()!=null){
			whereWrapper.eq("due_time",where.getDue_time());
		}
        if(where.getInvite_code()!=null){
			whereWrapper.eq("invite_code",where.getInvite_code());
		}
        if(where.getParent_id()!=null){
			whereWrapper.eq("parent_id",where.getParent_id());
		}
        if(where.getParent_parent_id()!=null){
			whereWrapper.eq("parent_parent_id",where.getParent_parent_id());
		}
        if(where.getUser_type()!=null){
			whereWrapper.eq("user_type",where.getUser_type());
		}
        if(where.getIs_trial()!=null){
			whereWrapper.eq("is_trial",where.getIs_trial());
		}
        if(where.getOperator_id()!=null){
			whereWrapper.eq("operator_id",where.getOperator_id());
		}
        if(where.getSelf_mention_point()!=null){
			whereWrapper.eq("self_mention_point",where.getSelf_mention_point());
		}
        if(where.getTotal_sales_amount()!=null){
			whereWrapper.eq("total_sales_amount",where.getTotal_sales_amount());
		}
        if(where.getTeam_sales_amount()!=null){
			whereWrapper.eq("team_sales_amount",where.getTeam_sales_amount());
		}
        if(where.getTotal_commission()!=null){
			whereWrapper.eq("total_commission",where.getTotal_commission());
		}
        if(where.getAvailable_commission()!=null){
			whereWrapper.eq("available_commission",where.getAvailable_commission());
		}
        if(where.getUsed_commission()!=null){
			whereWrapper.eq("used_commission",where.getUsed_commission());
		}
        if(where.getPending_commission()!=null){
			whereWrapper.eq("pending_commission",where.getPending_commission());
		}
        if(where.getFreeze_commission()!=null){
			whereWrapper.eq("freeze_commission",where.getFreeze_commission());
		}
        if(where.getEncrypt_key()!=null){
			whereWrapper.eq("encrypt_key",where.getEncrypt_key());
		}
        if(where.getProvince_id()!=null){
			whereWrapper.eq("province_id",where.getProvince_id());
		}
        if(where.getRegimental_qr_code()!=null){
			whereWrapper.eq("regimental_qr_code",where.getRegimental_qr_code());
		}
        if(where.getRegimental_desc()!=null){
			whereWrapper.eq("regimental_desc",where.getRegimental_desc());
		}
        if(where.getRegimental_atlas()!=null){
			whereWrapper.eq("regimental_atlas",where.getRegimental_atlas());
		}
        if(where.getLast_login_time()!=null){
			whereWrapper.eq("last_login_time",where.getLast_login_time());
		}
        if(where.getLast_login_ip()!=null){
			whereWrapper.eq("last_login_ip",where.getLast_login_ip());
		}
        if(where.getLast_buy_time()!=null){
			whereWrapper.eq("last_buy_time",where.getLast_buy_time());
		}
        if(where.getUp_time()!=null){
			whereWrapper.eq("up_time",where.getUp_time());
		}
        if(where.getIs_verificationer()!=null){
			whereWrapper.eq("is_verificationer",where.getIs_verificationer());
		}
        if(where.getIs_authentication()!=null){
			whereWrapper.eq("is_authentication",where.getIs_authentication());
		}
        if(where.getLive_player_type()!=null){
			whereWrapper.eq("live_player_type",where.getLive_player_type());
		}
        if(where.getIs_official_live_player()!=null){
			whereWrapper.eq("is_official_live_player",where.getIs_official_live_player());
		}
        if(where.getLive_player_status()!=null){
			whereWrapper.eq("live_player_status",where.getLive_player_status());
		}
        if(where.getLive_player_name()!=null){
			whereWrapper.eq("live_player_name",where.getLive_player_name());
		}
        if(where.getLive_player_wx_account()!=null){
			whereWrapper.eq("live_player_wx_account",where.getLive_player_wx_account());
		}
        if(where.getLive_player_fans_num()!=null){
			whereWrapper.eq("live_player_fans_num",where.getLive_player_fans_num());
		}
        if(where.getLive_player_open_time()!=null){
			whereWrapper.eq("live_player_open_time",where.getLive_player_open_time());
		}
        if(where.getLive_player_remarks()!=null){
			whereWrapper.eq("live_player_remarks",where.getLive_player_remarks());
		}
        if(where.getIs_syxhz()!=null){
			whereWrapper.eq("is_syxhz",where.getIs_syxhz());
		}
        return whereWrapper;
    }

    private QueryWrapper<JbrUsersView> InitWrapperView(JbrUsersView where){
        QueryWrapper<JbrUsersView> whereWrapper = new QueryWrapper<JbrUsersView>();
        if(where.getId()!=null){
			whereWrapper.eq("id",where.getId());
		}
        if(where.getUser_name()!=null){
			whereWrapper.eq("user_name",where.getUser_name());
		}
        if(where.getMobile()!=null){
			whereWrapper.eq("mobile",where.getMobile());
		}
        if(where.getLogin_pass()!=null){
			whereWrapper.eq("login_pass",where.getLogin_pass());
		}
        if(where.getMobile_check()!=null){
			whereWrapper.eq("mobile_check",where.getMobile_check());
		}
        if(where.getEmail()!=null){
			whereWrapper.eq("email",where.getEmail());
		}
        if(where.getEmail_check()!=null){
			whereWrapper.eq("email_check",where.getEmail_check());
		}
        if(where.getScore()!=null){
			whereWrapper.eq("score",where.getScore());
		}
        if(where.getScore_total()!=null){
			whereWrapper.eq("score_total",where.getScore_total());
		}
        if(where.getAmount()!=null){
			whereWrapper.eq("amount",where.getAmount());
		}
        if(where.getPay_pass()!=null){
			whereWrapper.eq("pay_pass",where.getPay_pass());
		}
        if(where.getAlias()!=null){
			whereWrapper.eq("alias",where.getAlias());
		}
        if(where.getSex()!=null){
			whereWrapper.eq("sex",where.getSex());
		}
        if(where.getBirthday()!=null){
			whereWrapper.eq("birthday",where.getBirthday());
		}
        if(where.getQq()!=null){
			whereWrapper.eq("qq",where.getQq());
		}
        if(where.getReg_date()!=null){
			whereWrapper.eq("reg_date",where.getReg_date());
		}
        if(where.getReg_source()!=null){
			whereWrapper.eq("reg_source",where.getReg_source());
		}
        if(where.getNote()!=null){
			whereWrapper.eq("note",where.getNote());
		}
        if(where.getIsok()!=null){
			whereWrapper.eq("isok",where.getIsok());
		}
        if(where.getImg_url()!=null){
			whereWrapper.eq("img_url",where.getImg_url());
		}
        if(where.getQq_id()!=null){
			whereWrapper.eq("qq_id",where.getQq_id());
		}
        if(where.getQq_name()!=null){
			whereWrapper.eq("qq_name",where.getQq_name());
		}
        if(where.getQq_img_url()!=null){
			whereWrapper.eq("qq_img_url",where.getQq_img_url());
		}
        if(where.getWx_id()!=null){
			whereWrapper.eq("wx_id",where.getWx_id());
		}
        if(where.getWx_name()!=null){
			whereWrapper.eq("wx_name",where.getWx_name());
		}
        if(where.getWx_img_url()!=null){
			whereWrapper.eq("wx_img_url",where.getWx_img_url());
		}
        if(where.getXcx_id()!=null){
			whereWrapper.eq("xcx_id",where.getXcx_id());
		}
        if(where.getXcx_formid()!=null){
			whereWrapper.eq("xcx_formid",where.getXcx_formid());
		}
        if(where.getUnion_id()!=null){
			whereWrapper.eq("union_id",where.getUnion_id());
		}
        if(where.getGrade_id()!=null){
			whereWrapper.eq("grade_id",where.getGrade_id());
		}
        if(where.getStart_time()!=null){
			whereWrapper.eq("start_time",where.getStart_time());
		}
        if(where.getDue_time()!=null){
			whereWrapper.eq("due_time",where.getDue_time());
		}
        if(where.getInvite_code()!=null){
			whereWrapper.eq("invite_code",where.getInvite_code());
		}
        if(where.getParent_id()!=null){
			whereWrapper.eq("parent_id",where.getParent_id());
		}
        if(where.getParent_parent_id()!=null){
			whereWrapper.eq("parent_parent_id",where.getParent_parent_id());
		}
        if(where.getUser_type()!=null){
			whereWrapper.eq("user_type",where.getUser_type());
		}
        if(where.getIs_trial()!=null){
			whereWrapper.eq("is_trial",where.getIs_trial());
		}
        if(where.getOperator_id()!=null){
			whereWrapper.eq("operator_id",where.getOperator_id());
		}
        if(where.getSelf_mention_point()!=null){
			whereWrapper.eq("self_mention_point",where.getSelf_mention_point());
		}
        if(where.getTotal_sales_amount()!=null){
			whereWrapper.eq("total_sales_amount",where.getTotal_sales_amount());
		}
        if(where.getTeam_sales_amount()!=null){
			whereWrapper.eq("team_sales_amount",where.getTeam_sales_amount());
		}
        if(where.getTotal_commission()!=null){
			whereWrapper.eq("total_commission",where.getTotal_commission());
		}
        if(where.getAvailable_commission()!=null){
			whereWrapper.eq("available_commission",where.getAvailable_commission());
		}
        if(where.getUsed_commission()!=null){
			whereWrapper.eq("used_commission",where.getUsed_commission());
		}
        if(where.getPending_commission()!=null){
			whereWrapper.eq("pending_commission",where.getPending_commission());
		}
        if(where.getFreeze_commission()!=null){
			whereWrapper.eq("freeze_commission",where.getFreeze_commission());
		}
        if(where.getEncrypt_key()!=null){
			whereWrapper.eq("encrypt_key",where.getEncrypt_key());
		}
        if(where.getProvince_id()!=null){
			whereWrapper.eq("province_id",where.getProvince_id());
		}
        if(where.getRegimental_qr_code()!=null){
			whereWrapper.eq("regimental_qr_code",where.getRegimental_qr_code());
		}
        if(where.getRegimental_desc()!=null){
			whereWrapper.eq("regimental_desc",where.getRegimental_desc());
		}
        if(where.getRegimental_atlas()!=null){
			whereWrapper.eq("regimental_atlas",where.getRegimental_atlas());
		}
        if(where.getLast_login_time()!=null){
			whereWrapper.eq("last_login_time",where.getLast_login_time());
		}
        if(where.getLast_login_ip()!=null){
			whereWrapper.eq("last_login_ip",where.getLast_login_ip());
		}
        if(where.getLast_buy_time()!=null){
			whereWrapper.eq("last_buy_time",where.getLast_buy_time());
		}
        if(where.getUp_time()!=null){
			whereWrapper.eq("up_time",where.getUp_time());
		}
        if(where.getIs_verificationer()!=null){
			whereWrapper.eq("is_verificationer",where.getIs_verificationer());
		}
        if(where.getIs_authentication()!=null){
			whereWrapper.eq("is_authentication",where.getIs_authentication());
		}
        if(where.getLive_player_type()!=null){
			whereWrapper.eq("live_player_type",where.getLive_player_type());
		}
        if(where.getIs_official_live_player()!=null){
			whereWrapper.eq("is_official_live_player",where.getIs_official_live_player());
		}
        if(where.getLive_player_status()!=null){
			whereWrapper.eq("live_player_status",where.getLive_player_status());
		}
        if(where.getLive_player_name()!=null){
			whereWrapper.eq("live_player_name",where.getLive_player_name());
		}
        if(where.getLive_player_wx_account()!=null){
			whereWrapper.eq("live_player_wx_account",where.getLive_player_wx_account());
		}
        if(where.getLive_player_fans_num()!=null){
			whereWrapper.eq("live_player_fans_num",where.getLive_player_fans_num());
		}
        if(where.getLive_player_open_time()!=null){
			whereWrapper.eq("live_player_open_time",where.getLive_player_open_time());
		}
        if(where.getLive_player_remarks()!=null){
			whereWrapper.eq("live_player_remarks",where.getLive_player_remarks());
		}
        if(where.getIs_syxhz()!=null){
			whereWrapper.eq("is_syxhz",where.getIs_syxhz());
		}
        return whereWrapper;
    }

    /**
     * 会员表新增
     * @param model 会员表实体
     * @return 影响行数
     */
	@Override
    public Integer add(JbrUsers model){
        return jbrUsersMapper.insert(model);
    }

    /**
     * 会员表修改byid
     * @param model 会员表实体
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUsers model) {
        return jbrUsersMapper.updateById(model);
    }

    /**
     * 会员表修改by条件
     * @param model 会员表实体
     * @param where 会员表条件
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUsers model, Wrapper<JbrUsers> where) {
        return jbrUsersMapper.update(model, where);
    }

    /**
     * 会员表修改by条件-自动封装Wrapper
     * @param model 会员表实体
     * @return 影响行数
     */
	@Override
    public Integer update(JbrUsers model, JbrUsers where) {
        Wrapper<JbrUsers> wrapper = InitWrapper(where);
        return update(model, wrapper);
    }

    /**
     * 会员表修改bySQL *version_id = newVersion where version_id = oldVersion
     * @param fields 修改的数据 col1=xx,col2=yy
     * @param where 参数化条件 col1=#{col1}
     * @param params 条件参数 col1=xx
     * @return 影响行数
     */
	@Override
    public Integer update(Map<String, Object> fields, String where, Map<String, Object> params) {
        return dbHelper.update("jbr_users", fields, where, params);
    }

    /**
     * 会员表删除byid
     * @param id 会员表主键
     * @return 影响行数
     */
	@Override
    public Integer del(int id) {
        return jbrUsersMapper.deleteById(id);
    }

    /**
     * 会员表删除by条件
     * @param where 会员表条件
     * @return 影响行数
     */
	@Override
    public Integer del(Wrapper<JbrUsers> where) {
        return jbrUsersMapper.delete(where);
    }

    /**
     * 会员表删除by条件-自动封装Wrapper
     * @param where 会员表条件
     * @return 影响行数
     */
    @Override
    public Integer del(JbrUsers where) { 
        Wrapper<JbrUsers> wrapper = InitWrapper(where);
        return del(wrapper);
    }

    /**
     * 会员表批量删除byid
     * @param ids 会员表主键集合
     * @return 影响行数
     */
	@Override
    public Integer del(List<Integer> ids){
        return jbrUsersMapper.deleteBatchIds(ids);
    }

    /**
     * 会员表批量删除bymap条件
     * @param map 会员表map条件
     * @return 影响行数
     */
	@Override
    public Integer del(Map<String,Object> map){
        return jbrUsersMapper.deleteByMap(map);
    }

    /**
     * 会员表详情byid
     * @param id 会员表主键
     * @return 会员表详情
     */
	@Override
    public JbrUsersView info(int id){
        return jbrUsersMapperView.selectById(id);
    }

    /**
     * 会员表详情by条件
     * @param where 会员表条件
     * @return 会员表详情
     */
	@Override
    public JbrUsersView info(Wrapper<JbrUsersView> where){
        return jbrUsersMapperView.selectOne(where);
    }

    /**
     * 会员表详情by条件-自动封装Wrapper
     * @param where 会员表条件
     * @return 会员表详情
     */
	@Override
    public JbrUsersView info(JbrUsersView where) {
        Wrapper<JbrUsersView> wrapper = InitWrapperView(where);
        return info(wrapper);
    }

    /**
     * 会员表详情bySQL
     * @param columns  列名col1,col2,col3^
     * @param where 条件 col1=#{col1}
     * @param params col1:xx
     * @param mappings col1->col1
     * @return
     */
	@Override
    public JbrUsers info(String columns, String where, Map<String, Object> params, ResultMapping mappings) {
        return dbHelper.selectOne(columns, "jbr_users", where, params, JbrUsers.class, mappings);
    }

    /**
     * 会员表批量查询byid
     * @param ids 会员表主键集合
     * @return 会员表列表
     */
	@Override
    public List<JbrUsersView> select(List<Integer> ids){
        return jbrUsersMapperView.selectBatchIds(ids);
    }

    /**
     * 会员表批量查询by条件
     * @param where 会员表条件
     * @return 会员表列表
     */
	@Override
    public List<JbrUsersView> select(Wrapper<JbrUsersView> where){
        return jbrUsersMapperView.selectList(where);
    }

    /**
     * 会员表批量查询by条件-自动封装Wrapper
     * @param where 会员表条件
     * @return 会员表列表
     */
    @Override
    public List<JbrUsersView> select(JbrUsersView where) {
        Wrapper<JbrUsersView> wrapper = InitWrapperView(where);		
        return select(wrapper);
    }

    /**
     * 会员表批量查询bymap条件
     * @param map 会员表map条件
     * @return 会员表列表
     */
	@Override
    public List<JbrUsersView> select(Map<String,Object> map){
        return jbrUsersMapperView.selectByMap(map);
    }

    /**
     * 会员表批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
	@Override
    public IPage<JbrUsersView> select(IPage<JbrUsersView> page, Wrapper<JbrUsersView> where){
        return jbrUsersMapperView.selectPage(page, where);
    }

    /**
     * 会员表批量查询b条件分页
     * @param page 分页条件
     * @param where 查询条件
     * @return
     */
    @Override
    public IPage<JbrUsersView> select(IPage<JbrUsersView> page, JbrUsersView where) {
		Wrapper<JbrUsersView> wrapper = InitWrapperView(where);		
        return select(page, wrapper);
    }

    /**
     * 会员表查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(Wrapper<JbrUsersView> where){
        return jbrUsersMapperView.selectCount(where);
    }

    /**
     * 会员表查询记录数
     * @param where 查询条件
     * @return
     */
	@Override
    public Integer selectCount(JbrUsersView where){
		Wrapper<JbrUsersView> wrapper = InitWrapperView(where);
        return selectCount(wrapper);
    }

    /**
     * 会员表批量查询bySQL条件分页
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param orderBy 排序字段
     * @param params 参数化 col1=xx
     * @param pageNumber 分页页码
     * @param pageSize 每页行数
     * @param mappings 查询列和实体映射
     * @return 分页之后的数据含总行数
     */
	@Override
    public DataPage<JbrUsersView> select(String columns, String where, String orderBy, Map<String, Object> params, int pageNumber, int pageSize, ResultMapping mappings){
        return dbHelper.select(columns, "jbr_users", where, orderBy, params, pageNumber, pageSize, JbrUsersView.class,mappings);
    }

    /**
     * 会员表批量查询bySQL条件
     * @param columns 列col1,col2,col3……
     * @param where 条件col1=#{col1} and col2=#{col2}
     * @param params 参数化 col1=xx
     * @param mappings 查询列和实体映射
     * @return 栏目扩展列表
     */
	@Override
    public List<JbrUsersView> select(String columns, String where, Map<String, Object> params, ResultMapping mappings){
        return dbHelper.select(columns,"jbr_users",where,params,JbrUsersView.class,mappings);
    }
}